package com.stock.stockana;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.stock.stockana.ui.activities.MainActivity;
import com.stock.stockana.ui.activities.StockDetailActivity;

/**
 * ---------------------------------------------------
 * Description: 接受jpush推送通知的广播接收器
 * Author: ljgsonx
 * Belong to: com.stock.stockana
 * Time: 2016/2/4 14:08
 * ---------------------------------------------------
 */
public class JPushNotifiReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
//        Bundle bundle = intent.getExtras();
//        String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
//        if(StringUtil.isBlank(extras)) return;
//        PushedStock ps = JSON.parseObject(extras, PushedStock.class);
//        if(ps == null) return;
//        if (MainActivity.instance != null) {
//            MainActivity.instance.finish();
//            MainActivity.instance = null;
//        }
//        Intent newIntent = new Intent(context, MainActivity.class);
//        newIntent.putExtra("pushedStockNum", ps.getStNum());
//        newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        context.startActivity(newIntent);
        if (MainActivity.instance != null) {
            MainActivity.instance.finish();
            MainActivity.instance = null;
        }
        if (StockDetailActivity.instance != null) {
            StockDetailActivity.instance.finish();
            StockDetailActivity.instance = null;
        }
        Intent newIntent = new Intent(context, MainActivity.class);
        newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        newIntent.putExtra("push", 1);
        context.startActivity(newIntent);
    }
}
